from flask import request,redirect,url_for,render_template
from main import app
from main.models import Task
from flask_login import current_user
@app.route('/',methods=['GET','POST'])
def main():
    return render_template('blog/index.html')
@app.route('/index/',methods=['GET','POST'])
def index():
    page = request.args.get('page', 1, type=int)
    per_page = app.config['BLUELOG_POST_PER_PAGE']
    pagination = Task.query.order_by(Task.start_time.desc()).paginate(page, per_page=per_page)
    tasks = pagination.items
    print("tasks:",tasks)
    return render_template('blog/index.html',tasks=tasks,pagination=pagination)
@app.route('/task/<int:task_id>', methods=['GET', 'POST'])
def show_task(task_id):
    task = Task.query.get_or_404(task_id)
    page = request.args.get('page', 1, type=int)
    per_page = app.config['BLUELOG_COMMENT_PER_PAGE']
    if current_user.is_authenticated:
        from_admin = True
    else:
        return redirect(url_for('login'))
    return render_template('blog/task.html')
